﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using DLV.Utilities;

namespace DLV.Data.Entities
{
    public class TourController
    {
        public int InsertTour(TourInfo info)
        {
            return SQL.InsertTour(info.TourName, info.TourTypeId, info.GroupType, info.LocationBegin, info.Schedule, info.QuantityAdult, info.QuantityChild, info.BeginDate, info.EndDate, info.QuantityDay, info.QuantityNight, info.CreatedBy, info.CreatedDate, info.UpdatedBy, info.UpdatedDate, info.Status, info.Season, info.MartName, info.QuantityBaby, info.HasLandTour, info.MaTour, info.TourCity);
        }
        public void UpdateTour(TourInfo info)
        {
            SQL.UpdateTour(info.TourId, info.TourName, info.TourTypeId, info.GroupType, info.LocationBegin, info.Schedule, info.QuantityAdult, info.QuantityChild, info.BeginDate, info.EndDate, info.QuantityDay, info.QuantityNight, info.CreatedBy, info.CreatedDate, info.UpdatedBy, info.UpdatedDate, info.Status, info.Season, info.MartName, info.QuantityBaby, info.HasLandTour, info.MaTour, info.TourCity);
        }
        public void DeleteTour(TourInfo info)
        {
            DeleteTour(info.TourId);
        }
        public void DeleteTour(int tourId)
        {
           SQL.DeleteTourFullTourId(tourId);
            SQL.DeleteTour(tourId);
        }

        public TourInfo GetTour(int tourId)
        {
            return CBO.FillObject<TourInfo>(SQL.GetTour(tourId));
        }
        public List<TourInfo> ListTour()
        {
            return CBO.FillCollection<TourInfo>(SQL.ListTour());
        }
        public List<TourInfo> ListTourSearch( TourInfo info, byte cusStatus)
        {
            return CBO.FillCollection<TourInfo>(SQL.ListTourSearch(info.MaTour,
                                                                 info.TourName,
                                                                 info.TourTypeId,
                                                                 info.GroupType,
                                                                 info.Schedule,
                                                                 info.MartName,
                                                                 info.HasLandTour,
                                                                 //info.CTBeginDate,
                                                                 info.CTSeasion ,
                                                                 info.QuantityDay,
                                                                  cusStatus
                                                                 ) );
        }
        public List<TourInfo> CalculatorTourList(TourInfo info, byte cusStatus)
        {
            var tourInfo = CBO.FillCollection<TourInfo>(SQL.CalculatorTourList(  ));
            //if (info.MaTour != "")
            //   tourInfo = tourInfo.Where(p =>  p.MaTour.Contains(info.MaTour) ).ToList() ;
            if (info.TourName != "")
                tourInfo = tourInfo.Where(p => p.TourName.Contains(info.TourName)).ToList();
            //if (info.TourTypeId >0)
            //    tourInfo = tourInfo.Where(p => p.TourTypeId == info.TourTypeId).ToList();
            //if (info.GroupType != "-1")
            //    tourInfo = tourInfo.Where(p => p.GroupType == info.GroupType).ToList();
            //if (info.Schedule != "-1")
            //    tourInfo = tourInfo.Where(p => p.Schedule == info.Schedule).ToList();
            //if (info.MartName != "-1")
            //    tourInfo = tourInfo.Where(p => p.MartName == info.MartName).ToList();
            //if (info.CTSeasion != "-1")
            //    tourInfo = tourInfo.Where(p => p.CTSeasion == info.CTSeasion).ToList();
            //if (info.QuantityDay > 0)
            //    tourInfo = tourInfo.Where(p => p.QuantityDay == info.QuantityDay).ToList();

            return tourInfo;
        }
        public DataTable SelectTour()
        {
            return CBO.ConvertToDataTable(ListTour(), typeof(TourInfo));
        }
        public DataTable SelectTourByHasLandTour(int hasLandTour)
        {
            return CBO.ConvertToDataTable(ListTour().Where(p=>p.HasLandTour==hasLandTour).ToList(), typeof(TourInfo));
        }
        public Dictionary<object, object> ListTourLookup()
        {
            var pages = ListTour();
            return pages.ToDictionary<TourInfo, object, object>(info => info.TourId, info => info.TourName);
        }

        public TourInfo CalculatorTourGet(int cTId)
        {
            return CBO.FillObject<TourInfo>(SQL.CalculatorTourGet(cTId));
        }
    }
}
